﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
//using FOBVT.Web.MainClass;
using System.Collections;

namespace FOBVT.Web.FOBVT2011.cn
{
    public partial class RegistrationFee : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!IsPostBack)
            //{
                try
                {
                    string info = "";
                    if (FOBVT.Web.MainClass.SessionState.CurrentUser == null)
                    {
                        System.Data.OleDb.OleDbConnection Conn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("..\\..\\DB\\FOBVTweb.mdb"));
                        FOBVT.Web.MainClass.GetUserInfo user = new FOBVT.Web.MainClass.GetUserInfo();
                        user.Conn = Conn;
                        FOBVT.Web.MainClass.User userInfo = user.GetUserInfoForPDF(Request["customerId"]);
                        FOBVT.Web.MainClass.SessionState.CurrentUser = userInfo;
                        info = string.Format("{0} {1} :", userInfo.FirstName, userInfo.LastName);
                        this.lblUserID.Text = Request["customerId"];
                    }
                    else
                    {
                        //Get this user registration ID;
                        info = string.Format("{0} {1} :", FOBVT.Web.MainClass.SessionState.CurrentUser.FirstName, FOBVT.Web.MainClass.SessionState.CurrentUser.LastName);
                        this.lblUserID.Text = FOBVT.Web.MainClass.SessionState.CurrentUser.CustomerID;

                    }
                    this.LabelName.Text = info;
                    switch (FOBVT.Web.MainClass.SessionState.CurrentUser.State)
                    {
                        case 4:
                            this.BtnPayFee.Enabled = false;
                            this.BtnDownloadDoc.Enabled = true;
                            break;
                        case 5:
                            this.BtnPayFee.Enabled = false;
                            this.BtnDownloadDoc.Enabled = true;
                            break;
                        default:
                            this.BtnPayFee.Enabled = true;
                            this.BtnDownloadDoc.Enabled = false;
                            break;

                    }
                }

                catch
                {
                    Response.Redirect("login.aspx");
                }
            //}
        }

        private void UpdateInfo()
        {
            System.Data.OleDb.OleDbConnection Conn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("..\\..\\DB\\FOBVTweb.mdb"));
            FOBVT.Web.MainClass.DBClass DBClassTmp = new FOBVT.Web.MainClass.DBClass();
            ArrayList sql = new ArrayList();
            sql.Clear();
            sql.Add("UPDATE  CustomerInfo SET StatusID='5',Status='CreatePDF',CreatPDFTime=#" + System.DateTime.Now.ToString() +
              "# WHERE (CustomerID ='"+ FOBVT.Web.MainClass.SessionState.CurrentUser.CustomerID +"')");

            if (!DBClassTmp.ExcuteSQL(sql, Conn))
            {
                this.LabError.Text = "E";
                
            }
        }

        protected void BtnCreatePDF_Click(object sender, EventArgs e)
        {
            //form1.Target = "_";
            if (FOBVT.Web.MainClass.SessionState.CurrentUser.State == 4)
            {
                UpdateInfo();
            }
           
        }

        private string GetEnglishFormatDateInfo(DateTime inputStr)
        {
            string outputStr = "";
            if (inputStr != null)
            {
                System.Globalization.CultureInfo c = System.Globalization.CultureInfo.CreateSpecificCulture("en");
                outputStr = inputStr.ToString("D", c.DateTimeFormat);
                outputStr = outputStr.Substring(outputStr.IndexOf(',') + 1);
            }
            return outputStr;
        }

      

        protected void BtnDownloadDoc_Click(object sender, EventArgs e)
        {
            Response.Redirect("/PDF/hotel_booking_form.doc");
        }

        protected void BtnPayFee_Click(object sender, EventArgs e)
        {
            Response.Redirect("ChinaBank.aspx");
        }
    }
}